import { defineAsyncComponent, onMounted, onUnmounted, type Component, type ComponentPublicInstance } from 'vue';

export default class VueHelper {
  static async defineAsyncComponent<T extends Component = {
    new(): ComponentPublicInstance;
  }>(url: string, loadingComponent?: Component, errorComponent?: Component): Promise<T> {
    // Sets default components.
    // loadingComponent ??= LoadingComponent;
    // errorComponent ??= ErrorComponent;

    return defineAsyncComponent<T>({
      // the loader function
      loader: () => import(url),
      // A component to use while the async component is loading.
      loadingComponent: loadingComponent,
      // Delay before showing the loading component. Default: 200ms.
      delay: 200,
      // A component to use if the load fails
      errorComponent: errorComponent,
      // The error component will be displayed if a timeout is
      // provided and exceeded. Default: Infinity.
      timeout: 3000,
    })
  }
}